const state = {
  enviroment: {
    current: null
  },
  workspace: {
    current: null
  },
  directory: {
    isEdit: false,
    array: [],
    openeds: []
  },
  request: {
    array: [],
    current: {
      id: '',
      name: 'new_request',
      folderId: '',
      isNew: false
    }
  }
}

const mutations = {
  setEnviroment(state, payload){
    state.enviroment.current = payload
  },
  setWorkSpace(state, payload){
    state.workspace.current = payload
  },
  expanded(state, payload){
    state.directory.openeds.push(payload)
  },
  addDirectory(state, payload){
    state.directory.isEdit = true
    var directory = {
      id: '',
      name: '',
      type: -1,
      parentId: payload.id,
      isEditing: true,
      items: []
    }
    if(payload.items){
      payload.items.push(directory)
    } else{
      state.directory.array.push(directory)
    }
  },
  updateDirectory(state, payload){
    state.directory.isEdit = true
    payload.isEditing = true
  },
  setDirectory(state, payload){
    state.directory.array = payload
  },
  addRequest(state, payload){
    state.directory.isEdit = true
    var directory = {
      id: '',
      name: 'new_request',
      type: 0,
      parentId: payload.id,
      isEditing: false,
      items: []
    }
    payload.items.push(directory)
  }
}

export default {
  namespaced: true,
  state,
  mutations
}
